package live.ifox.factory;

import android.os.Environment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class EnvironmentInfo {
    private List<Map<String, Object>> infoModel;

    public EnvironmentInfo() {
        infoModel = new ArrayList<>();
    }

    private void addItem(String label, String type) {
        Map<String, Object> map = new HashMap<>();
        map.put("label", label);
        String path = Environment.getExternalStoragePublicDirectory(type).getAbsolutePath();
        map.put("detail", path);
        infoModel.add(map);
    }

    private void appendItem(String label, Object detail) {
        Map<String, Object> map = new HashMap<>();
        map.put("label", label);
        map.put("detail", detail);
        infoModel.add(map);
    }

    public List<Map<String, Object>> getModel() {
        addItem("Alarms", Environment.DIRECTORY_ALARMS);
        addItem("DCIM", Environment.DIRECTORY_DCIM);
        addItem("Documents", Environment.DIRECTORY_DOCUMENTS);
        addItem("Downloads", Environment.DIRECTORY_DOWNLOADS);
        addItem("Movies", Environment.DIRECTORY_MOVIES);
        addItem("Music", Environment.DIRECTORY_MUSIC);
        addItem("notifications ", Environment.DIRECTORY_NOTIFICATIONS);
        addItem("Pictures", Environment.DIRECTORY_PICTURES);
        addItem("Podcasts", Environment.DIRECTORY_PODCASTS);
        addItem("Ringtones", Environment.DIRECTORY_RINGTONES);
        appendItem("Data", Environment.getDataDirectory().getAbsolutePath());
        appendItem("Cache", Environment.getDownloadCacheDirectory().getAbsolutePath());
        appendItem("System", Environment.getRootDirectory().getAbsolutePath());

        if (isSDCardMounted()) {
            appendItem("ExternalStorage",
                    Environment.getExternalStorageDirectory().getAbsolutePath());
        }
        return infoModel;
    }

    private boolean isSDCardMounted() {
        return Environment.getExternalStorageState()
                .equals(Environment.MEDIA_MOUNTED);
    }
}
